﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.EntityValidation
{
    public class  LengthAttribute :NotNullAttribute
    {

        public int  Min  { get; set; }
        public int Max  { get; set; }
        public LengthAttribute()
        {
            ErrorMessage = "请输入正确的长度";
        }
        public override bool Verify(object o)
        {
            int length = 0;
            if (o == null)
            {

                length = 0;
            }else
            {

                length= o.ToString().Length;
            }
            var a = true;
            var b = true;
            if (Min == 0 && Max == 0)
            {

                return length == 0;
            }
             if (Min != 0  )
            {
                a= (length < Convert.ToInt32(Min));
            }
            if (Max != 0 )
            {

                b = (Convert.ToInt32(Max) > length);
            }
            return a && b; ;
        }
    }
}
